<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Banner extends Model
{
    protected $table = 'banner';


    protected static function boot()
    {
        parent::boot();

        static::updating(function ($banner){

            $cover = $banner->banner_url;


            if(! preg_match('/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is',$cover)){



                if (substr($cover,0,8) == './banner'){
                    $cover = substr($cover,9);

                }

                $banner->banner_url = url('api/bannerImage/'.$cover);
            }

            $banner->add_time = time();


        });
    }

}
